
var selectedItems = new Array();

function initContentTable(id)
{
	var table = document.getElementById(id);
	var rows = table.rows;
	for(var i = 0; i < rows.length; i++){
		if(rows[i].id !=0){
			/*rows[i].onclick = function() {
	            rowClicked(this);
	        }*/
			if(rowSelected(rows[i])){
				rows[i].className = "selected";
			}
		}
	}
}

function rowClicked(row){
	if(!rowSelected(row)){
		row.className = "selected";
		selectedItems.push(row.id.substr(3));
	}else{
		unselect(row.id.substr(3))
		row.className = "";
	}
}

function rowSelected(row){
	var itemid = row.id.substr(3);
	for(var i=0;i<selectedItems.length;i++){
		if(itemid == selectedItems[i]){
			return true;
		}
	}
	return false;
}

function unselect(id){
	for(var i=0;i<selectedItems.length;i++){
		if(id == selectedItems[i]){
			selectedItems.splice(i,1);
		}
	}
}

function toggleInfoDisplay(show){
	
	var link = $("#toggleColumnsLink");
	
	if (show){
		link.text("Hide");
		link.attr('onclick', "toggleInfoDisplay(false)");
		toggleElement('columnsDiv');
	} else {
		link.text("Edit Columns");		
		link.attr('onclick', "toggleInfoDisplay(true)");
		toggleElement('columnsDiv');
	}
}

function toggleElement(id){
	var element = $('#'+id)
	if (element != null)
	{
			element.toggle('blind');
			if (element.css('visibility') == 'visible')
				element.css('visibility', 'hidden');
			else 
				element.css('visibility', 'visible');
	}
}

function toggleColumn(name)
{
	var column = $('td.'+name);
	
	if (column.css('display') == 'table-cell')
	{
		changecss('td.'+name,'display','none');
	}
	else {		
		changecss('td.'+name,'display','table-cell');	
	}
	
}

function changecss(theClass,element,value) {
	//Last Updated on July 4, 2011
	//documentation for this script at
	//http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
	 var cssRules;


	 for (var S = 0; S < document.styleSheets.length; S++){


		  try{
		  	document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);

		  } catch(err){
		  		try{document.styleSheets[S].addRule(theClass,element+': '+value+';');

				}catch(err){

				 	try{
					    if (document.styleSheets[S]['rules']) {
						  cssRules = 'rules';
						 } else if (document.styleSheets[S]['cssRules']) {
						  cssRules = 'cssRules';
						 } else {
						  //no rules found... browser unknown
						 }

						  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
						   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
						    if(document.styleSheets[S][cssRules][R].style[element]){
						    document.styleSheets[S][cssRules][R].style[element] = value;
							break;
						    }
						   }
						  }
					  } catch (err){}



				}

		  }


	}
}
